package edu.hainnu.niit.service.Impl;

import edu.hainnu.niit.dao.AuctionDao;
import edu.hainnu.niit.model.PageBean;
import edu.hainnu.niit.model.Product;
import edu.hainnu.niit.model.auction;
import edu.hainnu.niit.service.IAuctionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * TODO
 *
 * @package_name edu.hainnu.niit.service.Impl
 * @auther GGB
 * @date 2021/12/22
 * @time 10:46
 */
@Service
public class AuctionServiceImpl implements IAuctionService {
    @Resource
    AuctionDao auctionDao;
    @Override
    public PageBean<auction> queryAuctionsService(Integer currentPage, Integer pageSize,String sname) {
        PageBean<auction> pageBean =new PageBean<auction>();
        pageBean.setCurrentPage(currentPage);
        pageBean.setPageSize(pageSize);

        int Count = auctionDao.queryAuctionTotal(sname);
        pageBean.setTotalCount(Count);

        int totalPage = Count % pageSize == 0 ? Count / pageSize :(Count / pageSize) + 1 ;
        pageBean.setTotalPage(totalPage);

        currentPage=(currentPage-1)*pageSize;
        pageBean.setList(auctionDao.queryAuctions(currentPage,pageSize,sname));
        return pageBean;
    }

    @Override
    public PageBean<auction> queryTypeAuctionsService(Integer currentPage, Integer pageSize, String Type,String sname) {
        PageBean<auction> pageBean =new PageBean<auction>();
        pageBean.setCurrentPage(currentPage);
        pageBean.setPageSize(pageSize);

        int Count = auctionDao.queryTypeAuctionTotal(Type,sname);
        pageBean.setTotalCount(Count);

        int totalPage = Count % pageSize == 0 ? Count / pageSize :(Count / pageSize) + 1 ;
        pageBean.setTotalPage(totalPage);

        currentPage=(currentPage-1)*pageSize;
        pageBean.setList(auctionDao.queryTypeAuctions(currentPage,pageSize,Type,sname));
        return pageBean;
    }

    @Override
    public auction queryAuctionByIDService(Integer id) {
        return auctionDao.queryAuctionByID(id);
    }
}
